package cj.web.portal.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cj.web.kly.domain.Columns;
import cj.web.kly.domain.News;
import cj.web.kly.domain.Subject;
import cj.web.kly.domain.SubjectColumns;
import cj.web.kly.domain.SubjectNews;
import cj.web.portal.dao.ColumnsVoDAO;
import cj.web.portal.dao.NewsVoDAO;
import cj.web.portal.dao.SubjectColumnsVoDAO;
import cj.web.portal.dao.SubjectVoDAO;

@Service
public class SpecialTopicService {

	@Autowired
    private NewsVoDAO newsVoDAO;
	@Autowired
    private SubjectVoDAO subjectVoDAO;
	@Autowired
    private SubjectColumnsVoDAO subjectColumnsVoDAO;
	@Autowired
    private ColumnsVoDAO columnsVoDAO;
	
	/**
	 * 查询栏目信息
	 * @param columnsId
	 * @return
	 */
	public SubjectColumns querySubjectColumns(int subjectColumnsId){
		return subjectColumnsVoDAO.queryById(subjectColumnsId);
	}
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	public List<SubjectNews> queryListById(int subjectColumnsId,int start,int length){
		List<SubjectNews> newslis = newsVoDAO.querySubject(subjectColumnsId, start, length);
		return newslis;
    }
	
	/**
	 * 专题信息
	 * @param subjectId
	 * @return
	 */
	public Map querySubjectColumnslis(int subjectId){
		Map rep = new HashMap();
		//专题信息
		Subject subject = subjectVoDAO.queryById(subjectId);
		//查询组织部门信息
		List<SubjectColumns> subjectColumnslis = subjectColumnsVoDAO.queryAll(subjectId);
		
		rep.put("subject", subject);
		rep.put("subjectColumnslis", subjectColumnslis);
		return rep;
	}
	
	public Map querySubjectColumnslis(int subjectId,int subjectColumnsId){
		Map rep = new HashMap();
		//专题信息
		Subject subject = subjectVoDAO.queryById(subjectId);
		//专题栏目页
		SubjectColumns subjectColumns = subjectColumnsVoDAO.queryById(subjectColumnsId);
		//查询组织部门信息
		List<SubjectColumns> subjectColumnslis = subjectColumnsVoDAO.queryAll(subjectId);
		
		rep.put("subject", subject);
		rep.put("subjectColumns", subjectColumns);
		rep.put("subjectColumnslis", subjectColumnslis);
		return rep;
	}
	
	/**
	 * 专题列表
	 * @param subjectId
	 * @param start
	 * @param length
	 * @return
	 */
	public Map query(int subjectColumnsId,int start,int length){
		Map rep = new HashMap();
		List<SubjectNews> newslis = newsVoDAO.querySubject(subjectColumnsId, start, length);
		int size = newsVoDAO.querySubjectSize(subjectColumnsId);
		rep.put("newslis", newslis);
		rep.put("size", size);
		return rep;
    }
	
	/**
	 * 相关新闻
	 * @param columnsId
	 * @param start
	 * @param length
	 * @return
	 */
	public List<SubjectNews> querylis(int subjectColumnsId,int start,int length){
		return newsVoDAO.querySubject(subjectColumnsId, start, length);
	}
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	public News queryById(int id){
		News obj = newsVoDAO.queryById(id);
		newsVoDAO.addPV(id);
		return obj;
    }
	
	/**
	 * 
	 * @param id
	 * @return
	 */
	public SubjectNews querySubjectNewsById(int id){
		SubjectNews obj = newsVoDAO.querySubjectNewsById(id);
		newsVoDAO.addSubjectNewsPV(id);
		return obj;
    }
}